Database reference guide

HOME

NSQL Functions - A to Z

ABS

Removes the sign from each record in the column.

[RESULT] = ABS

Part Description
[RESULT] Data Type = INTEGER_FIELD or REAL_FIELD
[COLUMN] Data Type = INTEGER_FIELD or REAL_FIELD

ACOS

Returns the ArcCos of the column/value in Radians

[RESULT] = Sin([COLUMN])

Part Description
[RESULT] Data Type = REAL_FIELD
[COLUMN] Data Type = REAL_FIELD

AGE

Returns the number of years between two dates.

[RESULT] = AGE([DATEFIELD1] , [DATEFIELD2])

Part Description
[RESULT] Data Type = INTEGER_FIELD Age of [DATEFIELD1] at [DATEFIELD2]
[DATEFIELD1] Data Type = DATE_FIELD or DATETIME_FIELD
  • [FIELDNAME] of Field to get age for
[DATEFIELD2] Date at which to get the age. Can be either of the following:
  • [FIELDNAME] of data type DATE_FIELD or DATETIME_FIELD.

AGE

Returns the number of years between two dates.

[RESULT] = AGE([DATEFIELD1] , [DATEFIELD2])

Part Description
[RESULT] Data Type = INTEGER_FIELD Age of [DATEFIELD1] at [DATEFIELD2]
[DATEFIELD1] Data Type = DATE_FIELD or DATETIME_FIELD
  • [FIELDNAME] of Field to get age for
[DATEFIELD2] Date at which to get the age. Can be either of the following:
  • [FIELDNAME] of data type DATE_FIELD or DATETIME_FIELD.

Remarks

Both [DATEFIELD] parameters must be of the same data type, either DATE_FIELD or DATETIME_FIELD. Functions DATE and DATETIME can be used for data type conversion.

Examples

SELECT * FROM [TABLE] WHERE EXPR{AGE([DATEFIELD],[DATE])} < 50; SELECT * FROM [TABLE] WHERE EXPR{AGE(DATE([DATETIMEFIELD]),[DATEFIELD])} < 50;

ALLMONTHS

Returns the year and month parts of a date field, in the format CCYYMM (e.g. 199805 would be returned where the specified datefield contained a date which fell in May 1998).

[RESULT] = ALLMONTHS([DATEFIELD])

Part Description
[RESULT] Data Type = INTEGER_FIELD Year and month parts of [DATEFIELD]
[DATEFIELD] Data Type = DATE_FIELD, DATETIME_FIELD

ALLQUARTERS

Returns the year and quarter of a date field, in the format CCYYQQ (e.g. 199802 would be returned where the specified datefield contained a date which fell in the second quarter of 1998).

[RESULT] = ALLQUARTERS([DATEFIELD])

Part Description
[RESULT] Data Type = INTEGER_FIELD Year and quarter of [DATEFIELD]
[DATEFIELD] Data Type = DATE_FIELD, DATETIME_FIELD

ASIN

Returns the ArcSin of the column/value in Radians

[RESULT] = ASin([COLUMN])

Part Description
[RESULT] Data Type = REAL_FIELD
[COLUMN] Data Type = REAL_FIELD

ATAN

Returns the ArcTan of the column/value in Radians

[RESULT] = ATAN([COLUMN])

Part Description
[RESULT] Data Type = REAL_FIELD
[COLUMN] Data Type = REAL_FIELD

AVG

Returns the average value of a set of values.

[RESULT] = Avg([FIELDNAME])

Part Description
[RESULT] Data Type = INTEGER_FIELD, REAL_FIELD Average value of specified field.
[FIELDNAME] Data Type = INTEGER_FIELD, REAL_FIELD The field from which to obtain the average.

Examples

To return the average of the values in a column:

SELECT AVG([FIELD]) FROM [TABLE];

BIGINT

Returns the integer or whole number part of the input data, and returns the value as a BIGINT column. The number will be rounded to a whole number, eg: 1.7 will be returned as 2. Used in an expression to force the creation of a BIGINT_FIELD.

[RESULT] = BIGINT([VALUE])

Part Description
[RESULT] Data Type = BIGINT_FIELD
[VALUE] Input parameter can be any of the following:
  • String Literal: Converts the String to aBIGINT
  • Column contains String Data
  • Numeric Literal: Rounds up the number to the nearest INTEGER as a BIGINT

 

CEIL

Returns the smallest integer greater than or equal to a value.

[RESULT] = CEIL([NUMERICFIELD])

Part Description
[RESULT] Data Type = INTEGER_FIELD
[NUMERICFIELD] Data Type = INTEGER_FIELD, REAL_FIELD

Example

SELECT CEIL([Demo].[Order Detail].[Sale Price]) FROM [Demo].[Order Detail];

Returns 6 when Sale Price = 5.10.

Returns 6 when Sale Price = 5.50.

Returns 6 when Sale Price = 5.99.

See also

FLOOR function

CHR

Returns the ASCII character represented by a numeric column (mod 256).

[RESULT] = CHR([NUMERICFIELD])

Part Description
[RESULT] Data Type = TEXT_FIELD
[NUMERICFIELD] Data Type = REAL_FIELD, INTEGER_FIELD

CODE

Returns the ASCII code of the first character.

[RESULT] = CODE([FIELDNAME])

Part Description
[RESULT] Data Type = TEXT_FIELD
[FIELD] Data Type = TEXT_FIELD, INTEGER_FIELD, REAL_FIELD

CONTAINSALL

Returns all records where ALL of the tokens specified are present.

[RESULT] = ContainsAll([FIELDNAME]) [OPERATOR] [VALUE]

Part Description
[RESULT] Domain containing all valid records
[FIELDNAME] Name of an ARRAY FIELD (TEXT_FIELD where Format = VARRAY or FARRAY)
[OPERATOR] IN, =
[VALUE] Data Type = String
  • If not decoded, [VALUE] is one or more token values, e.g. "12" or "2","4"
  • If decoded, [VALUE] is the decoded value, e.g. "UK"
  • If more than one value is specified, the IN operator must be used, e.g. IN "UK","FRANCE"
  • "12" is the same as "21" - i.e. segment order is irrelevant in terms of returning the correct values

Example

The following query will return ALL records where the NON-DECODED field Question1 contains token 1 and 2 (including those where other values are also present):

The following query will return ALL records where the NON-DECODED field Question1 contains token 1 and 2 (including those where other values are also present):

The following query will return all records where the DECODED field Question1 contains the tokens "UK" and "FRANCE" (including those where other values are also present):

SELECT # FROM [Demo].[Customer] WHERE ContainsAll(Question1) IN "UK", "FRANCE";

Note the following is not a valid query:

SELECT # FROM [Demo].[Customer] WHERE ContainsAll(Question1) = "UK,FRANCE";

CONTAINSEXACTLY

Returns all records where the tokens contained match only those specified.

[RESULT] = ContainsExactly([FIELDNAME]) [OPERATOR] [VALUE]

Part Description
[RESULT] Domain containing all valid records
[FIELDNAME] Name of an ARRAY FIELD (TEXT_FIELD where Format = VARRAY or FARRAY)
[OPERATOR] IN, =
[VALUE] Data Type = String
  • If not decoded, [VALUE] is one or more token values, e.g. "12" or "2","4"
  • If decoded, [VALUE] is the decoded value, e.g. "UK"
  • If more than one value is specified the IN operator must be used, e.g. IN "UK","FRANCE"
  • "12" is the same as "21" - i.e. segment order is irrelevant in terms of returning the correct values

Example

To return records where the NON-DECODED field Question1 contains only the tokens 1 and 2 (in any order - i.e. 12 or 21):

SELECT # FROM [Demo].[Customer] WHERE ContainsExactly(Question1) = "12"; SELECT # FROM [Demo].[Customer] WHERE ContainsExactly(Question1) = "12";

The following query will return all records where the DECODED field Question1 contains only the token "UK":

SELECT # FROM [Demo].[Customer] WHERE ContainsExactly(Question1) = "UK";

The following query will return all records where the DECODED field Question1 contains BOTH "UK" and "FRANCE":

SELECT # FROM [Demo].[Customer] WHERE ContainsExactly(Question1) IN "UK", "FRANCE";

COS

Returns the Cos of the column/value in Radians

[RESULT] = Cos([COLUMN])

PartDescription
[RESULT] Data Type = REAL_FIELD
[COLUMN] Data Type = REAL_FIELD

COUNT

Returns the number of records or values in a set of values.

[RESULT] = Count([VALUE]) [EXPRESSION]

Part Description
[RESULT] Data Type = INTEGER_FIELD Number of records or values. Note - Count does NOT return columns for viewing.
[VALUE] String
  • * : Wildcard, will return a count of all rows returned by [EXPRESSION]
[EXPRESSION] Any valid FROM or WHERE statement. e.g. FROM [CUSTOMER] WHERE

Remarks

It is not possible to list more than one FIELD_NAME within the COUNT statement:

SELECT COUNT ([FIELD_NAME1], [FIELD_NAME2]) FROM [TABLE];

COUNT does not support embedded functions, for example:

SELECT COUNT (DISTINCT [FIELD_NAME2]) FROM [TABLE];

Example

To return the count of all rows in the table:

SELECT COUNT (*) FROM [TABLE];

COUNTTOKENS

Returns all records where the number of tokens matches the specified value.

[RESULT] = CountTokens([FIELDNAME]) [OPERATOR] [VALUE]

Part Description
[RESULT] Domain containing all valid records
[FIELDNAME] Name of an ARRAY FIELD (TEXT_FIELD where Format = VARRAY or FARRAY)
[OPERATOR] GT, GE , LT , LE , EQ , BETWEEN , XBETWEEN , NE
[VALUE] Data Type = Long Number of tokens If [VALUE] = 0, will return all records where no segments were specified. This is the same as using Is NULL.

Example

To return all records where the customer specified 3 or more answers for question 1:

SELECT # FROM [Demo].[Customer] WHERE CountTokens(Question1) => 3;

CUMUL

Returns the cumulative value of all column records or the running balance.

[RESULT] = CUMUL([FIELDNAME])

Part Description
[RESULT] Data Type = REAL_FIELD
[FIELD] Data Type = INTEGER_FIELD, REAL_FIELD

DATE

Returns the input data converted from formatted text to a DATE data type value. Used in an expression to force the creation of a DATE_FIELD.

[RESULT] = DATE( [VALUE] , [FORMAT])

Part Description
[RESULT] Data Type = DATE_FIELD
[VALUE] Input parameter can be any of the following:
  • Integer: If [VALUE] is an integer it is assumed that it refers to an INTERNAL DATE VALUE
  • Column: The column must contain formatted DATE or DATETIME data as Strings
[FORMAT] Optional. Format of [VALUE]. If omitted, then [VALUE] must be provided in a format matching the SystemDateFormat . If the FORMAT is specified, it must use the following codes:
  • CC = Century
  • YY = Year
  • MM = Month Numbers
  • MMM = 3 character months, such as "Jan", "Feb", "Jul" etc
  • DD = Day
e.g. DATE([Demo].[Table].[Date1], "CCYYDDMM")

Remarks

Note that regardless of the INPUT format (as specified by [FORMAT]) the data will be stored in the format specified by SystemDateFormat. It is this format that must be used when evaluating the DATE in expressions or queries.

Examples

If DOB is a string column in the format "CCYYMMDD" then:

SELECT DATE([Demo].[Person].[DOB]) FROM [Demo].[Person];

returns 13-08-2002 when DOB = 20021308.

DATETIME

Returns a DATETIME_FIELD representation of the input data. Used in an expression to force the creation of a DATETIME_FIELD. Supports 2 types of syntax:

Syntax1 [RESULT] = DATETIME([VALUE1])

Part Description
[RESULT] Data Type = DATETIME_FIELD
  • Returns NULL if [VALUE] cannot be converted to DATETIME format.
  • The Format of the RESULT is determined by the SystemDateTimeFormat.
[VALUE]
  • Column containing formatted DATETIME data as string. Date must be in format of SystemDateTimeFormat.
  • DATETIME literal in SystemDateTimeFormat.

Syntax2 [RESULT] = DATETIME([VALUE1], [VALUE2])

Part Description
[RESULT] Data Type = DATETIME_FIELD
  • Returns NULL if [VALUE] cannot be converted to DATETIME format.
  • The Format of the RESULT is determined by the SystemDateTimeFormat.
[VALUE1]
  • Column containing DATE data.
  • DATE literal in SystemDateFormat.
[VALUE2]
  • Column containing TIME data
  • TIME literal in SystemTimeFormat

Remarks

If no Date value is specified, or if the Date Value is NULL, then a base year of 1900 is used. If the TIME value is NULL or not specified then Midnight (00:00:00) will be used.

Examples

The following returns 10/12/1955 23:32:00 where :

  • DATETIMESTRING = 19551012 2332 and
  • SystemDateTimeFormat is "CCYYMMDD HHMM"

SELECT DATETIME([Demo].[Person].[DATETIMESTRING]) FROM [Demo].[Person];

The following returns 10/12/1955 23:32:14 where:

  • DATEFIELD1 = 10121955
  • TIMEFIELD1 = 233214
  • SystemDateFormat is "CCYYMMDD" and
  • SystemTimeFormat is "HHMMSS"

SELECT DATETIME([Demo].[Person].[DATEFIELD1],[Demo].[Person].[TIMEFIELD1] ) FROM [Demo].[Person];

DAY

Returns the day portion of each record (1-31).

[RESULT] = DAY([DATECOLUMN])

Part Description
[RESULT] Data Type = INTEGER_FIELD
[DATECOLUMN] Data Type = DATE_FIELD, DATETIME_FIELD

Examples

If DOB is a date column in the format "DDMMCCYY" then:

SELECT DAY([Demo].[Person].[DOB]) FROM [Demo].[Person];

returns 13 when DOB = 13082006.

DAYAT

Adds or subtracts (with minus sign) [integer] number of days to/from a date field.

[RESULT] = DAYAT([DATEFIELD], integer)

Part Description
[RESULT] Data Type = DATE_FIELD, DATETIME_FIELD
[DATEFIELD] Data Type = DATE_FIELD, DATETIME_FIELD

Examples

If DOB is a date column in the format "DDMMCCYY" then:

SELECT DAYAT([Demo].[Person].[DOB], 30) FROM [Demo].[Person];

returns 22022006 when DOB = 23012006.

DAYSTO

Returns the number of days between 2 dates.

[RESULT] = DAYSTO([PARAM1], [PARAM2])

Part Description
[RESULT] Data Type = INTEGER_FIELD Number of days between [PARAM1] and [PARAM2]
[PARAM1] Data Type = DATE_FIELD or String
  • [FIELDNAME] of Date Field for first date
[PARAM2] Data Type = DATE_FIELD or String
  • [FIELDNAME] of Date Field for second date

Remarks

Both parameters must be of the same data type, either DATE_FIELD or DATETIME_FIELD. Functions DATE and DATETIME can be used for data type conversion.

Examples

SELECT * FROM [TABLE] WHERE DAYSTO([FIELD1],[FIELD2])< 200;

DISTANCE

Calculates the distance between two geographic points.

[RESULT] = DISTANCE([FIELDNAME], [Value])

Part Description
[RESULT] Data Type = REAL_FIELD
[FIELDNAME] Data Type = TEXT_FIELD, INTEGER_FIELD, REAL_FIELD
[Value] Data Type = Same as [FIELDNAME] Must be a geographic value that exists in [FIELDNAME], e.g. a postcode.

Remarks

Requires Mapping configuration settings in Cerberus.Ini.

Example

SELECT Count(*) FROM [Customers] WHERE DISTANCE([Postcode],'BS2 9AG') < 1609;

DISTANCEBETWEEN

Returns the Great Circle Distance between two Latitude, Longitude points.

Part Description [RESULT] Data Type = REAL_FIELD [Lat1] Data Type = REAL_FIELD [Long1] Data Type = REAL_FIELD [Lat2] Data Type = REAL_FIELD [Long2] Data Type = REAL_FIELD Unit Fixed integer

Returns the Great Circle Distance between two Latitude, Longitude points.

[RESULT] = DISTANCEBETWEEN("[Lat1],[Long1], [Lat2],[Long2],Unit")

Part Description

[RESULT]

Data Type = REAL_FIELD

[Lat1]

Data Type = REAL_FIELD

[Long1]

Data Type = REAL_FIELD

[Lat2]

Data Type = REAL_FIELD

[Long2]

Data Type = REAL_FIELD

Unit

Fixed integer

Unit may be:

0: Nautical Miles

1: Meters

2: Kilometers

3: Statute Miles

4: Feet

5: Yards

6: Radians

Note that the parameters are specified as a single quoted string rather than as separate parameters.

DIGEST

Returns the 128bit MD5 hash of one or more columns.

[RESULT] = DIGEST(“[COLUMN_1], [COLUMN_2],…, [COLUMN_N])

Part Description
[RESULT] Data Type = TEXT_FIELD
[COLUMN] Data Type = ANY

Remarks

Digest can be used to create a compound key of multiple columns without having to resort to column concatenation.

The probability of a hash collision is very low, but cannot be absolutely guaranteed.

Note that the Digest expression can take any reasonable number of columns as input but these are formed as a single quoted string rather than as separate parameters.

Example

EXPRESSION [Demo].[Customer] , MyKey , {DIGEST("[Cust ID],[Household ID],Age")}

DISTINCT

Returns the record position of each value in a column's sorted list of distinct values.

[RESULT] = DISTINCT([FIELDNAME])

Part Description
[RESULT] Data Type = INTEGER_FIELD
[FIELDNAME] Data Type = Any

Example

For a column containing the following records:

[ Record Number] [Town]
0 Bristol
1 Birmingham
2 Bristol
3 Birmingham
4 Birmingham
5 Bath
6 Bath
7 Bristol
8 Birmingham
9 Bath

SELECT EXPR{ DISTINCT([Town]) }, [Town] FROM [Demo].[Customer];

returns:

[Record Number] [Expr] [Town]
0 3 Bristol
1 2 Birmingham
2 3 Bristol
3 2 Birmingham
4 2 Birmingham
5 1 Bath
6 1 Bath
7 3 Bristol
8 2 Birmingham
9 1 Bath

since in a sorted, distinct list, Bath is in position 1, Birmingham in position 2, and Bristol in position 3.

EODAY

Returns the end of the day of a date or datetime value, plus or minus a day offset.

[RESULT] = EODAY([COLUMN],dayOffset)

Part Description
[RESULT] Data Type = DATE_FIELD,DATETIMEFIELD
[COLUMN] Data Type = DATE_FIELD,DATETIMEFIELD

Example

End of current day

EXPRESSION [Demo].[Customer] , DayEnd , {EODAY(DOB,0)}

End of previous day

EXPRESSION [Demo].[Customer] , YesterdayEnd , {EOMONTH(DOB,-1)}

EOMONTH

Returns the end of the month of a date or datetime value, plus or minus a month offset.

[RESULT] = EOMONTH([COLUMN],monthOffset)

Part Description
[RESULT] Data Type = DATE_FIELD,DATETIMEFIELD
[COLUMN] Data Type = DATE_FIELD,DATETIMEFIELD

Example

End of current month:

EXPRESSION [Demo].[Customer] , MonthEnd , {EOMONTH(DOB,0)}

End of Previous month:

EXPRESSION [Demo].[Customer] , PrevMonthEnd , {EOMONTH(DOB,-1)}

EXP

Returns the exponential of each column record. The column must hold numeric values.

Returns the exponential of each column record. The column must hold numeric values.

Part Description
[RESULT] Data Type = REAL_FIELD
[NUMERIC_COLUMN] Data Type = INTEGER_FIELD, REAL_FIELD

FIRSTQUARTILE

Returns the value at the first quartile of the column.

[RESULT] = FIRSTQUARTILE([NUMERIC_COLUMN])

Part Description
[RESULT] Data Type = REAL_FIELD
[NUMERIC_COLUMN] Data Type = INTEGER_FIELD, REAL_FIELD

Example

For a column containing 20 records with values 1 to 20, the following NSQL would return 5.00:

SELECT FIRSTQUARTILE([COLUMN]) FROM [DB].[TABLE];

FLOOR

Returns the largest integer less than or equal to each record.

[RESULT] = FLOOR([COLUMN])

Part Description
[RESULT] Data Type = INTEGER_FIELD
[COLUMN] Data Type = REAL_FIELD, INTEGER_FIELD

Example

SELECT FLOOR([Demo].[Order Detail].[Sale Price]) FROM [Demo].[Order Detail];

Returns 5 when Sale Price = 5.10.

Returns 5 when Sale Price = 5.50.

Returns 5 when Sale Price = 5.99

See also

CEIL function

HOUR

Returns the hours part of a datetime or time column, in 24-hour format.

[RESULT] = HOUR([DATETIME_COLUMN])

Part Description
[RESULT] Data Type = INTEGER_FIELD
[DATETIME_COLUMN] Data Type = DATETIME_FIELD, TIME_FIELD

Example

Given a table of bank transactions, the following would return all transactions that took place between 9 am and 3 pm:

SELECT Count(*) FROM [Transaction] WHERE HOUR([Transaction_Time]) BETWEEN 9 and 15;

INSTR

Returns the numeric position in a column of the characters specified by a string.

[RESULT] = INSTR([COLUMN], [STRING])

Part Description
[RESULT] Data Type = INTEGER_FIELD The position at which the first character of [STRING] appears within [COLUMN].
[COLUMN] Data Type = TEXT_FIELD The field to search in.
[STRING] Data Type = String The string to search for

Remarks

The position of the first character of [COLUMN] is 1. If [STRING] is not found, 0 is returned.

The search is case sensitive.

Example

If you were to search for the word "East" in a column holding the names of regions in the UK:

SELECT INSTR([Demo].[Household].[Regions], "East") FROM [Demo].[Household];

returns 0 when [Demo].[Household].[Regions] is Channel Islands.

returns 1 when [Demo].[Household].[Regions] is East Midlands.

returns 7 when [Demo].[Household].[Regions] is South East.

INT

Returns the integer or whole number part of the input data. The number will be rounded to a whole number, eg: 1.7 will be returned as 2. Used in an expression to force the creation of an INTEGER_FIELD.

[RESULT] = INT([VALUE])

Part Description
[RESULT] Data Type = INTEGER_FIELD
[VALUE] Input parameter can be any of the following:
  • String Literal: Converts the String to an INTEGER
  • Column contains String Data
  • Numeric Literal: Rounds up the number to the nearest INTEGER

Remarks

Numbers are rounded to the nearest whole numbers. For example, 1.7 will be rounded up to 2, 1.3 will be rounded down to 1.0 and 1.5 will be rounded up to 2.

If a column contains a value that cannot be converted into an integer, the value will be stored as NULL or 0.

Examples

The following returns 1001 when code = "1001":

SELECT INT([Demo].[Person].[code]) FROM [Demo].[Person];

ISNULL

Returns 0 where the column holds null, and 1 where the value is not null.

[RESULT] = ISNULL([COLUMN])

Part Description
[RESULT] Data Type = INTEGER_FIELD
[COLUMN] Data Type = TEXT_FIELD, INTEGER_FIELD, REAL_FIELD, DATE_FIELD, DATETIME_FIELD, TIME_FIELD

Example

The following returns a count of customers where the Surname field contains null:

SELECT Count(*) FROM [Demo].[Customers] WHERE ISNULL([Demo].[Customers].[Surname]) = 1;

IURN

Returns the Internal Engine URN for a record.

[RESULT] = IURN([VALUE]) [EXPRESSION]

Part Description
[RESULT] Data Type = INTEGER_FIELD Internal URN for each record.
[VALUE] String
  • [FIELDNAME] : Name or NameEx of primary key on table
[EXPRESSION] Any valid FROM or WHERE statement. Must include the owner table of the Field specified in [VALUE] e.g. SELECT IURN([Demo].[Customer].[FID]) FROM [Customer];

Remarks

Every record in every table has an internal URN. Engine URNs are 0 based.

When used in the WHERE clause of a query, must use EXPR{} syntax.

Examples

To return the Internal URN of all rows in the table:

SELECT IURN(FID) FROM [TABLE];

To delete the first 20 rows of a table:

DELETE * FROM [TABLE] WHERE EXPR{IURN([DB].[TABLE].[FID])} BETWEEN 0 and 19;

KURTOSIS

Returns a value indicating the kurtosis of a column.

[RESULT] = KURTOSIS([COLUMN])

Part Description
[RESULT] Data Type = REAL_FIELD
[COLUMN] Data Type = INTEGER_FIELD, REAL_FIELD

LCASE

Returns the values of a text column in all lower case.

[RESULT] = LCASE([COLUMN])

Part Description
[RESULT] Data Type = TEXT_FIELD
[COLUMN] Data Type = TEXT_FIELD

Examples

The following query:

SELECT LCASE([Demo].[Customer].[Surname]) FROM [Demo].[Customer];

returns smith when Surname = Smith

returns smith when Surname = SMITH

returns smith when Surname = smith

LEFT

Returns a specified number of characters from the left of a text column.

[RESULT] = LEFT([COLUMN], [NUMBER])

Part Description
[RESULT] Data Type = TEXT_FIELD
[COLUMN] Data Type = TEXT_FIELD, UNICODE_FIELD The column from which to return a substring.
[NUMBER] Data Type = Integer The number of characters to return.

LEN

Returns the length of each record in the column.

[RESULT] = LEN([COLUMN])

Part Description
[RESULT] Data Type = INTEGER_FIELD
[COLUMN] Data Type = TEXT_FIELD, INTEGER_FIELD, REAL_FIELD, UNICODE_FIELD

LOG

Returns the natural logarithm of the column records.

[RESULT] = LOG([COLUMN])

Part Description
[RESULT] Data Type = REAL_FIELD
[COLUMN] Data Type = INTEGER_FIELD, REAL_FIELD

LOG10

Returns the base 10 logarithm of the column records.

[RESULT] = LOG10([COLUMN])

Part Description
[RESULT] Data Type = REAL_FIELD
[COLUMN] Data Type = INTEGER_FIELD, REAL_FIELD

LTRIM

Returns the values of a text column after removing any spaces to the left of the column.

[RESULT] = LTRIM([COLUMN])

Part Description
[RESULT] Data Type = TEXT_FIELD, UNICODE_FIELD
[COLUMN] Data Type = TEXT_FIELD, UNICODE_FIELD

MAX

Returns the maximum value of a set of values.

[RESULT] = MAX([FIELDNAME])

Part Description
[RESULT] Data Type = DATE_FIELD, TIME_FIELD, DATETIME_FIELD, INTEGER_FIELD, REAL_FIELD Maximum value of specified field.
[FIELDNAME] Data Type = DATE_FIELD, TIME_FIELD, DATETIME_FIELD, INTEGER_FIELD, REAL_FIELD The field from which to obtain the maximum.

Examples

To return the maximum value from all values in a column:

SELECT MAX([FIELD) FROM [TABLE];

MAXIMUM

Returns whichever is the greater of two values.

[RESULT] = MAXIMUM([COLUMN], [COLUMN])

Part Description
[RESULT] Data Type = Same as [COLUMN]
[COLUMN] Data Type = Any
[COLUMN] Data Type = Any

MEAN

Returns the average value of a set of values.

[RESULT] = Mean([FIELDNAME])

Part Description
[RESULT] Data Type = REAL_FIELD Average value of specified field.
[FIELDNAME] Data Type = INTEGER_FIELD, REAL_FIELD The field to obtain the average of.

Examples

To return the average of all values in a column:

SELECT MEAN([NUMERICFIELD) FROM [TABLE];

MEDIAN

Returns the middle value of the column.

[RESULT] = MEDIAN([COLUMN])

Part Description
[RESULT] Data Type =
[COLUMN] Data Type =

MID

Returns a substring from each record of the column.

[RESULT] = MID([COLUMN], [NUMBER], [NUMBER])

Part Description
[RESULT] Data Type = Same as [COLUMN] A substring of [COLUMN].
[COLUMN] Data Type = TEXT_FIELD, UNICODE_FIELD The string column from which to obtain a substring.
[NUMBER] Data Type = INTEGER The start position in the string to return characters from, 1-based. If the start position is greater than the number of characters in the string, a zero-length string is returned.
[NUMBER] Data Type = INTEGER The number of characters to return from the string. If this is greater than the length of the string, all characters from the start position to the end of the string are returned.

MIN

Returns the minimum value of a set of values.

[RESULT] = Min([FIELDNAME])

Part Description
[RESULT] Data Type = Matches that of [FIELDNAME] column Minimum value of specified field.
[FIELDNAME] Data Type = DATE_FIELD, TIME_FIELD, DATETIME_FIELD, INTEGER_FIELD, REAL_FIELD The field from which to obtain the minimum.

Examples

To return the minimum value from all values in a column:

SELECT MIN([FIELD) FROM [TABLE];

MINIMUM

Returns whichever is the lower of two values.

[RESULT] = MINIMUM([COLUMN], [COLUMN])

Part Description
[RESULT] Data Type = Same as [COLUMN]
[COLUMN] Data Type = Any
[COLUMN] Data Type = Any

MINUTE

Returns the minutes part of a datetime or time column.

[RESULT] = MINUTE([DATETIME_COLUMN])

Part Description
[RESULT] Data Type = INTEGER_FIELD
[DATETIME_COLUMN] Data Type = DATETIME_FIELD, TIME_FIELD

MODE

Returns the value that occurs most often in a column.

[RESULT] = MODE([COLUMN])

Part Description
[RESULT] Data Type =
[COLUMN] Data Type =

MONTH

Returns the month portion of each record (1-12).

[RESULT] = MONTH([DATE_COLUMN])

Part Description
[RESULT] Data Type =
[DATE_COLUMN] Data Type =

NORMALISED

Returns the normalized value of each record in the column, defined as the difference between each value and the average value, divided by the standard deviation.

[RESULT] = NORMALISED([COLUMN])

Part Description
[RESULT] Data Type = REAL_FIELD
[COLUMN] Data Type = INTEGER_FIELD, REAL_FIELD

PAREA

Returns the Postal Area from a UK-Style postcode. The postal area is the first 2 letters, or the first letter if the 2nd character is a number. Parameter can be a string or a column containing postcodes.

[RESULT] = PAREA([PARAM])

Part Description
[RESULT] Data Type =
[PARAM] Data Type =

Examples

SELECT PAREA([Demo].[Person].[Postcode]) FROM [Demo].[Person]

Returns "CF" for "CF64 1AU" and "B" for "B1 8NN"

PDIST

Returns the Postal District from a UK-Style postcode. The Postal District is the postcode minus the last three chars, with all spaces removed. Parameter can be a string or a column containing postcodes.

[RESULT] = PDIST([PARAM])

Part Description
[RESULT] Data Type =
[PARAM] Data Type =

Examples

SELECT PDIST([Demo].[Person].[Postcode]) FROM [Demo].[Person]

Returns "PO1" for "PO1 3AX".

POWER

Returns each column record raised to the power of [number]

[RESULT] = POWER([COLUMN], [NUMBER])

Part Description
[RESULT] Data Type =
[COLUMN] Data Type =
[NUMBER] Data Type =

PROPER

Returns a column's data in initial capitals (ie lower case with a leading capital).

[RESULT] = PROPER([COLUMN])

Part Description
[RESULT] Data Type =
[COLUMN] Data Type =

PROPERSENTENCE

Returns a column's data in lower case but with a leading capital on every new word.

For example "the quick brown fox" would become "The Quick Brown Fox"

[RESULT] = PROPERSENTENCE([COLUMN])

Part Description
[RESULT] Data Type =
[COLUMN] Data Type =

PSECT

Returns the Postal Sector from a UK-Style postcode. The Postal Sector is the postcode minus the last two chars, with all spaces removed. The string [PARAM] is a string constant or the name of a column containing UK postcodes.

[RESULT] = PSECT([PARAM])

Part Description
[RESULT] Data Type =
[PARAM] Data Type =

Examples

SELECT PDIST([Demo].[Person].[Postcode]) FROM [Demo].[Person]

Returns "PO13" for "PO1 3AX".

QUARTER

Returns the quarter of the year for each record (1-4).

[RESULT] = QUARTER([DATE_COLUMN])

Part Description
[RESULT] Data Type =
[DATE_COLUMN] Data Type =

RAND

Returns a random number between 0 and the value of each record in the column.

[RESULT] = RAND([COLUMN])

Part Description
[RESULT] Data Type =
[COLUMN] Data Type =

REAL

Returns the integer or whole number part of the input data. Used in an expression to force the creation of a REAL_FIELD.

[RESULT] = REAL( [VALUE], [PRECISION] )

Part Description
[RESULT] Data Type = REAL_FIELD
  • Returns NULL if [VALUE] cannot be converted to REAL format
[VALUE] Input parameter can be any of the following:
  • Numeric Literal
  • Column containing REAL or INTEGER Data
  • String column containing numbers
[PRECISION] Optional
  • Sets the precision of the output data
  • Must be between 0 and 6
  • If not specified, precision defaults to the precision set by CO_DefaultPrecision in the Cerberus.Ini file

Remarks

If [PRECISION] is specified, then the function must be called within the EXPR{} syntax. Otherwise it can be called directly.

Examples

The following returns 10.00 when Income = "10" and DefaultPrecision = 2:

SELECT REAL([Demo].[Person].[Income]) FROM [Demo].[Person];

The following returns 10.000 when Income = 10:

SELECT EXPR{REAL([Demo].[Person].[Income],3) } FROM [Demo].[Person];

RIGHT

Returns [number] characters from the right of the column.

[RESULT] = RIGHT([COLUMN], [NUMBER])

Part Description
[RESULT] Data Type =
[COLUMN] Data Type =
[NUMBER] Data Type =

RMEAN

Returns the average value of a set of values as a Real.

[RESULT] = RMean( [FIELDNAME] )

Part Description
[RESULT] Data Type = REAL_FIELD Average value of specified field as a Real.
[FIELDNAME] Data Type = INTEGER_FIELD, REAL_FIELD The field to obtain the average of.

Examples

To return the average of all values in a column as a Real:

SELECT EXPR{RMEAN([NUMERICFIELD)} FROM [TABLE];

ROW

As for IURN.

[RESULT] = ROW([COLUMN])

Part Description
[RESULT] Data Type =
[COLUMN] Data Type =

RTRIM

Returns the values of a text column after removing any spaces to the right of the column.

[RESULT] = RTRIM([COLUMN])

Part Description
[RESULT] Data Type = TEXT_FIELD, UNICODE_FIELD
[COLUMN] Data Type = TEXT_FIELD, UNICODE_FIELD

SECOND

Returns the seconds part of a datetime or time column.

[RESULT] = SECOND([DATETIME_COLUMN])

Part Description
[RESULT] Data Type = INTEGER_FIELD
[DATETIME_COLUMN] Data Type = DATETIME_FIELD, TIME_FIELD

SGN

Returns the sign of each record, -1 for negative numbers, +1 for positive numbers or 0.

[RESULT] = SGN([COLUMN])

Part Description
[RESULT] Data Type =
[COLUMN] Data Type =

SIN

Returns the Sin of the column/value in Radians

[RESULT] = Sin([COLUMN])

Part Description
[RESULT] Data Type = REAL_FIELD
[COLUMN] Data Type = REAL_FIELD

SKEW

A measure of the skew of a column.

[RESULT] = SKEW([COLUMN])

Part Description
[RESULT] Data Type =
[COLUMN] Data Type =

SODAY

Returns the start of the day of a date or datetime value, plus or minus a day offset.

[RESULT] = SODAY([COLUMN],dayOffset)

Part Description
[RESULT] Data Type = DATE_FIELD,DATETIMEFIELD
[COLUMN] Data Type = DATE_FIELD,DATETIMEFIELD

Example

Start of current day

EXPRESSION [Demo].[Customer] , DayStart , {SODAY(DOB,0)}

End of previous day

EXPRESSION [Demo].[Customer] , YesterdayStart , {SODAY(DOB,-1)}

SOMONTH

Returns the start of the month of a date or datetime value, plus or minus a month offset.

[RESULT] = SOMONTH([COLUMN],monthOffset)

Part Description
[RESULT] Data Type = DATE_FIELD,DATETIMEFIELD
[COLUMN] Data Type = DATE_FIELD,DATETIMEFIELD

Example

Start of current month

EXPRESSION [Demo].[Customer] , MonthStart , {SOMONTH(DOB,0)}

End of previous month

EXPRESSION [Demo].[Customer] , PrevMonthStart , {SOMONTH(DOB,-1)}

SORTFORMAT

Converts a postcode to Sort Format in a column containing UK postcodes.

[RESULT] = SORTFORMAT([COLUMN])

Part Description
[RESULT] Data Type =
[COLUMN] Data Type =

SOUNDS

Returns the values of the column after removing all vowels (and Y) and spaces from the values.

[RESULT] = SOUNDS([COLUMN])

Part Description
[RESULT] Data Type =
[COLUMN] Data Type =

SQRT

Returns the square root of each record.

[RESULT] = SQRT([COLUMN])

Part Description
[RESULT] Data Type =
[COLUMN] Data Type =

STDEV

Returns the population standard deviation, i.e. the average amount by which a set of values deviates on either side of the mean.

[RESULT] = StDev([FIELDNAME])

Part Description
[RESULT] Data Type = REAL_FIELD Standard deviation of specified field.
[FIELDNAME] Data Type = INTEGER_FIELD, REAL_FIELD The field from which to obtain the standard deviation.

Examples

To return the standard deviation of the values in a column:

SELECT STDEV([FIELD) FROM [TABLE];

STDEVS

Returns the sample standard deviation of a column.

[RESULT] = STDEVS([COLUMN])

Part Description
[RESULT] Data Type =
[COLUMN] Data Type =

STRING

Returns a string representation of another data type. Used in an expression to force the creation of a TEXT_FIELD.

[RESULT] = String([VALUE])

Part Description
[RESULT] Data Type = TEXT_FIELD
[VALUE] Input parameter can be any valid data type or a fixed string.
  • Fixed String: String(12345) will return "12345"
  • Column: String([Demo].[Customer].[ID]) will convert the ID column to a text field.

Remarks

If the input is a Date, a Time or a DateTime the resulting string will be formatted in the user format , as specified in the Cerberus.ini file.

STRING will not convert Unicode data to ASCII format.

Examples

To return all records where [Database].[Table].[Field] = "JONES":

SELECT * FROM [Demo].[Table] WHERE STRING([Database].[Table].[Field])="JONES";

STRIP

Returns the values of the column after removing all spaces.

[RESULT] = STRIP([COLUMN])

Part Description
[RESULT] Data Type =
[COLUMN] Data Type =

SUM

Returns the sum of values in a set of values.

[RESULT] = Sum([FIELDNAME])

Part Description
[RESULT] Data Type = REAL_FIELD Sum of values.
[FIELDNAME] Data Type = INTEGER_FIELD or REAL_FIELD The field to sum.

Examples

To return the sum of all values in a column:

SELECT SUM([FIELD) FROM [TABLE];

SUMSQ

Returns the sum of squares of a set of values.

[RESULT] = SumSq([FIELDNAME])

Part Description
[RESULT] Data Type = REAL_FIELD Sum of squares of specified field.
[FIELDNAME] Data Type = INTEGER_FIELD, REAL_FIELD The field from which to obtain the sum of the squares

Examples

To return the sum of squares of the values in a column:

SELECT SUMSQ([NUMERICFIELD) FROM [TABLE];

TAN

Returns the Tan of the column/value in Radians

[RESULT] = TAN([COLUMN])

Part Description
[RESULT] Data Type = REAL_FIELD
[COLUMN] Data Type = REAL_FIELD

THIRDQUARTILE

Returns the value at the third quartile of the column.

[RESULT] = THIRDQUARTILE([COLUMN])

Part Description
[RESULT] Data Type =
[COLUMN] Data Type =

TIME

Returns a TIME_FIELD representation of the input data. Used in an expression to force the creation of a TIME_FIELD.

[RESULT] = TIME( [VALUE], [FORMAT] )

Part Description
[RESULT]

Data Type = TIME_FIELD

  • Returns NULL if [VALUE] cannot be converted to TIME format
  • The Format of the RESULT is determined by the SystemTimeFormat
[VALUE]

Input parameter can be any of the following:

  • Time Literal
  • Column containing formatted TIME data as string
  • Column containing DATETIME data
[FORMAT]

Optional

  • String specifying the format of the Input data:
    • HH = Hours
    • MM = Minutes
    • SS = Seconds
  • If not specified, FORMAT defaults to the Time format specified by SystemTimeFormat in the Cerberus.ini file.

Remarks

If [FORMAT] is not specified, and the input data is not fully qualified (i.e. instead of 01 a 1 is provided), the resulting time may not be correct.

[VALUE] [FORMAT] [RESULT]
3348 (03:03:48) NONE 03:34:08
13458 (13:45:09) NONE 01:34:59
224618 (22:26:18) NONE 22:26:18
3348 (03:03:48) HHMMSS NULL
13458 (13:45:09) HHMMSS NULL
224618 (22:26:18) HHMMSS 22:26:18
184622 (22:26:18) SSMMHH 22:26:18

If [FORMAT] is specified, Engine will only evaluate the expression for data that is fully qualified. This prevents incorrect formatting from being applied.

If [FORMAT] is specified, then the function must be called within the EXPR{} syntax. Otherwise it can be called directly.

When using a TIME_FIELD in an expression, note that hours are always stored as 24 hour.

Examples

The following returns 10:12:45 when TIMESTRING = "101245" and SystemTimeFormat is HHMMSS:

SELECT TIME([Demo].[Person].[TIMESTRING]) FROM [Demo].[Person];

The following returns 10:12 when TIMESTRING = "101245":

SELECT EXPR{REAL([Demo].[Person].[TIMESTRING],"HHMM") } FROM [Demo].[Person];

The following returns a count of transactions that occurred between 9am and 3pm:

SELECT COUNT(*) FROM [Demo].[Transaction] WHERE HOUR( [Demo].[Transaction].[TTIME] ) BETWEEN 9 and 15;

The following returns 10:12:45 where DATETIME1 = "19950613 1012":

SELECT TIME([Demo].[Person].[DATETIME1]) FROM [Demo].[Person];

Note that if the SystemDateTimeFormat

is 1 ( CCYYMMDD HHMM), it is still possible to extract HH:MM:SS data from the field.

TRIM

Returns the values of a text column after removing any spaces to the left and right of the column.

[RESULT] = TRIM([COLUMN])

Part Description
[RESULT] Data Type = TEXT_FIELD, UNICODE_FIELD
[COLUMN] Data Type = TEXT_FIELD, UNICODE_FIELD

Remarks

TRIM is not an NSQL function but can be used in NSQL with the Expr{} syntax:

SELECT EXPR{ TRIM([Demo].[Customer].[Town]) } FROM [Demo].[Customer];

UCASE

Returns the values of the column converted to upper case.

[RESULT] = UCASE([COLUMN])

Part Description
[RESULT] Data Type =
[COLUMN] Data Type =

WEEKDAY

Returns the day of the week for each record (1-7, with 1 being Monday).

[RESULT] = WEEKDAY([DATE_COLUMN])

Part Description
[RESULT] Data Type =
[DATE_COLUMN] Data Type =

WSTRING

Returns a string representation of another data type. Used in an expression to force the creation of a UNICODE_FIELD.

[RESULT] = String([VALUE])

Part Description
[RESULT] Data Type = UNICODE_FIELD
[VALUE] Input parameter can be any valid data type or a fixed string.
  • Fixed String: String(12345) will return "12345"
  • Column: String([Demo].[Customer].[ID]) will convert the ID column to a UNICODE text field.

Remarks

If the input is a Date, a Time or a DateTime the resulting string will be formatted in the user format , as specified in the Cerberus.ini file.

WSTRING will convert ASCII input to Unicode format.

Examples

The following will produce a Unicode version of the TOWN field:

SELECT WSTRING([Demo].[Table].[Town]) FROM [Demo].[Table];

YEAR

Returns the year portion of a date.

[RESULT] = YEAR([DATE_COLUMN])

Part Description
[RESULT] Data Type =
[DATE_COLUMN] Data Type =
  Online & Instructor-Led Courses | Training Videos | Webinar Recordings
© Alterian. All Rights Reserved. | Privacy Policy | Legal Notice